Problem Set: Binary Floating-Point Representation
Tags: #◇Computer Science #◇CSARCH2 #◇Computer Architecture #◇Problem Sets #◇IEEE-754 #◇Floating-Point Representation #◇Single Precision #◇Double Precision #◇Subnormal Numbers #◇Binary Conversion
◇Overview & Theoretical Foundations
In digital computing, fixed-point representations suffer from a severe dynamic range limitation: allocating a fixed number of integer and fractional bits restricts the range of numbers that can be represented. The IEEE-754 Standard for Floating-Point Arithmetic resolves this by representing real numbers in scientific notation:
IEEE-754 Single Precision (32-bit):
1 bit 8 bits 23 bits
┌──────┬──────────────────┬───────────────────────────────────────┐
│ Sign │ Biased Exponent │ Fraction (Mantissa) │
│ (S) │ (E) │ (F) │
└──────┴──────────────────┴───────────────────────────────────────┘
31 30 23 22 0
IEEE-754 Double Precision (64-bit):
1 bit 11 bits 52 bits
┌──────┬──────────────────┬───────────────────────────────────────┐
│ Sign │ Biased Exponent │ Fraction (Mantissa) │
│ (S) │ (E) │ (F) │
└──────┴──────────────────┴───────────────────────────────────────┘
63 62 52 51 0
1. Structural Parameters of IEEE-754 Formats
| Format | Total Bits () | Sign Bits () | Exponent Bits () | Exponent Bias | Actual Exponent Range () | Biased Exponent Range () | Fraction Bits () | Effective Precision () |
|---|---|---|---|---|---|---|---|---|
| Single Precision | 32 | 1 | 8 | () | 23 | 24 bits ( dec) | ||
| Double Precision | 64 | 1 | 11 | () | 52 | 53 bits ( dec) |
2. Classification of Representable Numbers
IEEE-754 partitions the exponent field into special regimes:
┌─────────────────┬──────────────────┐
│ E = 0 │ 1 <= E <= Emax │
├────────┬────────┼──────────────────┤
│ F = 0 │ F != 0 │ │
├────────┼────────┼──────────────────┤
│ Zero │Subnorm │ Normalized Number│
│ (+/-0) │(Denorm)│ │
└────────┴────────┴──────────────────┘
┌──────────────────┐
│ E = Emax │
├────────┬─────────┤
│ F = 0 │ F != 0 │
├────────┼─────────┤
│Infinity│ NaN │
│ (+/-oo)│(Quiet/ │
│ │Signal) │
└────────┴─────────┘
- Normalized Numbers ():
- Significand has an implicit leading bit of : .
- Unbiased exponent: .
- .
- Subnormal / Denormalized Numbers ():
- Used for gradual underflow to fill the gap between and the smallest normalized number.
- No implicit leading 1 (leading bit is ): .
- The unbiased exponent is fixed at: (i.e., for single, for double).
- .
- Signed Zero ():
- Represents () or ().
- Infinity ():
- Represents () or (), produced by overflow or division by zero.
- Not a Number / NaN ():
- Represents invalid operations (e.g., , ).
- Quiet NaN (QNaN): MSB of fraction is ().
- Signaling NaN (SNaN): MSB of fraction is ().
◇Problem Solutions
Problem 1: Convert to IEEE-754 Single Precision
Problem Statement
Represent the floating-point value using 32-bit single-precision binary format. Specify the sign bit, 8-bit exponent representation, 23-bit fraction, and hexadecimal representation.
Step-by-Step Derivation
-
Sign Bit ():
- The value is positive .
-
Exponent Analysis & Calculation:
- Unbiased exponent: .
- Single-precision bias: .
- Biased exponent:
- In single precision, the 8-bit exponent field can only represent integers from to ().
- Maximum finite normalized exponent is (which corresponds to ).
- Since (and ), this value exceeds the maximum representable finite number in IEEE-754 single precision.
-
IEEE-754 Standard Overflow Handling:
- Because of Exponent Overflow, the IEEE-754 standard maps this value to Positive Infinity ():
- (23 zeros)
- 32-bit pattern:
0 11111111 00000000000000000000000 - Hexadecimal:
0x7F800000
- Theoretical / Unbounded 9-Bit Exponent Derivation (Academic Context):
- If evaluated without clamping to standard single-precision overflow saturation:
- (9 bits).
- Truncated to 8 bits modulo 256: .
- Fraction (23 bits): .
Result Summary Table
| Field | IEEE-754 Standard (+ on Overflow) | Theoretical Exact (9-bit Exp Overflow) |
|---|---|---|
| Sign () | 0 | 0 |
| Exponent () | 11111111 () | 100000110 (, 9-bit) / 00000110 (8-bit trunc) |
| Fraction () | 00000000000000000000000 | 11010000000000000000000 |
| Hexadecimal | 0x7F800000 | OVERFLOW (or 0x03680000 modular) |
[!warning] Architecture Note
The maximum representable finite float in 32-bit single precision is . Since , it strictly overflows single precision.
Problem 2: Convert to IEEE-754 Double Precision
Problem Statement
Represent using 64-bit double-precision binary format.
Step-by-Step Derivation
-
Sign Bit ():
- Positive number .
-
Exponent Calculation:
- Unbiased exponent: .
- Double-precision bias: .
- Biased exponent:
- Convert to 11-bit binary:
- Check range: Valid normalized exponent.
-
Fraction Part ():
- Significand: .
- Implicit leading 1 is dropped, leaving fraction bits: .
- Pad with zeros to 52 bits:
-
Assemble 64-bit Binary Representation:
-
Convert to Hexadecimal (4-bit nibbles):
0100410008011061101D0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000000000000000- Hexadecimal:
0x486D000000000000
Result Summary Table
| Field | Binary Value | Description |
|---|---|---|
| Sign () | 0 | Positive ( bit) |
| Exponent () | 10010000110 | ( bits) |
| Fraction () | 1101000000000000000000000000000000000000000000000000 | bits |
| Hexadecimal | 0x486D000000000000 | Complete 64-bit word |
Problem 3: Convert to IEEE-754 Single Precision
Problem Statement
Represent using 32-bit single-precision format.
Step-by-Step Derivation
-
Sign Bit ():
- Positive number .
-
Exponent Analysis & Subnormal Detection:
- Unbiased exponent: .
- Single-precision bias: .
- Naive biased exponent:
- Because , this number cannot be represented as a normalized single-precision float (minimum normal exponent is with ).
- This value falls into the Subnormal (Denormalized) range!
-
Subnormal Representation Mechanism:
- In IEEE-754 subnormals:
- The exponent field is set to ().
- The implicit leading bit is rather than .
- The actual exponent is fixed to:
- We must equate:
- Solve for :
- Shifting right by positions:
- The 23-bit fraction field is:
- We must equate:
-
Assemble 32-bit Binary Layout:
- Bit 31 ():
0 - Bits 30–23 ():
00000000 - Bits 22–0 ():
00000000111010000000000
- Bit 31 ():
-
Convert to Hexadecimal:
- Hexadecimal:
0x00007400
- Hexadecimal:
Result Summary Table
| Field | Value | Notes |
|---|---|---|
| Sign () | 0 | Positive |
| Exponent () | 00000000 | indicates Subnormal / Denormalized |
| Fraction () | 00000000111010000000000 | bits () |
| Hexadecimal | 0x00007400 | IEEE-754 Subnormal Single Precision |
Problem 4: Convert to IEEE-754 Double Precision
Problem Statement
Represent using 64-bit double-precision format.
Step-by-Step Derivation
-
Sign Bit ():
- Positive number .
-
Exponent Calculation:
- Unbiased exponent: .
- Double-precision bias: .
- Biased exponent:
- Convert to 11-bit binary:
- Check range: Valid normalized double-precision number!
-
Fraction Part ():
- Significand: .
- Drop implicit leading 1: .
- Pad to 52 bits:
-
Assemble 64-bit Binary Representation:
-
Convert to Hexadecimal:
0011301117100081101D- Trailing 48 zero bits
000000000000 - Hexadecimal:
0x378D000000000000
Result Summary Table
| Field | Binary Value | Description |
|---|---|---|
| Sign () | 0 | Positive |
| Exponent () | 01101111000 | |
| Fraction () | 1101000000000000000000000000000000000000000000000000 | bits |
| Hexadecimal | 0x378D000000000000 | Normalized 64-bit Double Precision |
Problem 5: Decode Single-Precision 0xC1C20000 to Decimal
Problem Statement
Determine the equivalent fixed-point decimal value of the IEEE-754 single-precision floating-point bit pattern 0xC1C20000.
Step-by-Step Derivation
-
Convert Hexadecimal to 32-bit Binary:
-
Deconstruct IEEE-754 Single-Precision Fields:
- Sign Bit (, bit 31):
- Biased Exponent (, bits 30–23):
Unbiased exponent :
- Fraction Field (, bits 22–0):
Significand (with implicit leading 1):
- Sign Bit (, bit 31):
-
Compute Value in Binary Scientific Notation:
-
Shift Radix Point by Exponent ():
-
Convert Fixed-Point Binary to Decimal:
- Integer Part ():
- Fractional Part ():
- Combining with sign:
- Integer Part ():
Result Summary Table
| Field | Extraction | Value |
|---|---|---|
| Sign () | 1 | Negative () |
| Exponent () | 10000011 () | |
| Fraction () | 10000100000000000000000 | |
| Binary Fixed-Point | ||
| Decimal Equivalent | -24.25 | Exact decimal |
Problem 6: Decode Double-Precision 0x4027800000000000 to Decimal
Problem Statement
Determine the equivalent fixed-point decimal value of the IEEE-754 double-precision bit pattern 0x4027800000000000.
Step-by-Step Derivation
-
Convert Hexadecimal to 64-bit Binary:
-
Deconstruct IEEE-754 Double-Precision Fields:
- Sign Bit (, bit 63):
- Biased Exponent (, bits 62–52):
Unbiased exponent :
- Fraction Field (, bits 51–0):
Significand (with implicit leading 1):
- Sign Bit (, bit 63):
-
Compute Value in Binary Scientific Notation:
-
Shift Radix Point by Exponent ():
-
Convert Fixed-Point Binary to Decimal:
- Integer Part ():
- Fractional Part ():
- Combining:
- Integer Part ():
Result Summary Table
| Field | Extraction | Value |
|---|---|---|
| Sign () | 0 | Positive () |
| Exponent () | 010000000010 () | |
| Fraction () | 011110000000... | |
| Binary Fixed-Point | ||
| Decimal Equivalent | +11.75 | Exact decimal |
◇Python Verification Script
import struct
def verify_all():
# Problem 2
val2 = 1.8125 * (2.0 ** 135)
hex64_2 = f"0x{struct.unpack('>Q', struct.pack('>d', val2))[0]:016X}"
print(f"Prob 2: Expected 0x486D000000000000 -> Got {hex64_2} (Match: {hex64_2 == '0x486D000000000000'})")
# Problem 4
val4 = 1.8125 * (2.0 ** -135)
hex64_4 = f"0x{struct.unpack('>Q', struct.pack('>d', val4))[0]:016X}"
print(f"Prob 4: Expected 0x378D000000000000 -> Got {hex64_4} (Match: {hex64_4 == '0x378D000000000000'})")
# Problem 5
f5 = struct.unpack('>f', struct.pack('>I', 0xC1C20000))[0]
print(f"Prob 5: Expected -24.25 -> Got {f5} (Match: {f5 == -24.25})")
# Problem 6
f6 = struct.unpack('>d', struct.pack('>Q', 0x4027800000000000))[0]
print(f"Prob 6: Expected 11.75 -> Got {f6} (Match: {f6 == 11.75})")
verify_all()
◇Key Takeaways & Exam Summary
- Biased Exponent Formula: where .
- Single precision (): .
- Double precision (): .
- Special Exponent Codes:
- .
- .
- .
- .
- .
- Double Precision Cushion: Values that overflow or underflow single precision (e.g., ) easily fit within double precision normalized range ().